package com.itita.ww2.handler.eventhandler;

import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;
import com.itita.ww2.game.alliance.AllianceManager;
import com.itita.ww2.game.user.UserService;
import com.itita.ww2.model.user.UserProfile;
import com.itita.ww2.utils.UserUtil;

public class OnUserDisconnectHandler extends BaseServerEventHandler {

	@Override
	public void handleServerEvent(ISFSEvent event) throws SFSException {
		User user = (User) event.getParameter(SFSEventParam.USER);
		if (UserUtil.isGuest(user)) {
			return;
		}
		trace("[" + user.getName() + "] disconnect, save data...");
		UserProfile userProfile = UserService.getInstance().getUserProfile(user);
		if (userProfile == null)
			return;
		userProfile.onDisconnectEvent();
		// 
		AllianceManager.getInstance().removeAllianceUser(userProfile);
	}

}
